import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/promotion/column';


export interface ColumnParam {
    name?: string;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface ColumnResponse {
    id?: number;
    name: string;
    descs?: string;
    enterImg?: string;
    bannerImg?: string;
    status?: string;
    clickCount?: string;
    sort?: string;

    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface ColumnSaveCommand {
    id?: number;
    name: string;
    descs?: string;
    enterImg?: string;
    bannerImg?: string;
    status?: string;
    clickCount?: string;
    sort?: string;
}

export interface ColumnResponseList {
    list: ColumnResponse[];
    total: number;
}


// 通过ColumnParam参数获取分页列表
export function pageColumn(params: ColumnParam) {
    return axios.get<ColumnResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取专栏信息
export function getColumn(id: number) {
    return axios.get<ColumnResponse>(`${BASE_URL}/${id}`);
    
}

export function listColumn(params: ColumnParam) {
    return axios.get<ColumnResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}


// 添加专栏
export function addColumn(params: ColumnSaveCommand) {
    return axios.post(`${BASE_URL}`, params);
}

// 更新专栏
export function updateColumn(params: ColumnSaveCommand) {
    return axios.put(`${BASE_URL}`, params);
}

// 批量删除专栏
export function deleteColumn(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}